<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Help extends Model
{
    use HasFactory;

    protected $table = 'sp_help_2';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //根据类型获取一级分类
    protected function GetParentCategoryByEnabled($enabled)
    {
        $where = array(
            'enabled' => $enabled, //1常见问题 2商品发布教程 3租赁协议 4用户隐私协议 5供应商服务协议 6供应商帮助手册 7积分规则
            'parentid' => 0,
        );
        $select = array('id', 'parentid', 'name', 'content', 'enabled');
        $category = $this
            ->select($select)
            ->where($where)
            ->orderBy('displayorder', 'desc')
            ->first();
        $category = $category ? $category->toArray() : [];
        return $category;
    }

    //获取二级分类
    protected function GetSecondCategory($parentid)
    {
        $where = array(
            'parentid' => $parentid,
        );
        $select = array('id', 'parentid', 'name', 'content', 'enabled');
        $category = $this
            ->where($where)
            ->select($select)
            ->orderBy('displayorder', 'desc')
            ->get();
        $category = $category ? $category->toArray() : [];
        return $category;
    }
}
